<?php
class Roomcats
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */

    public function __construct()
    {
        $this->_db = Zend_Registry::get('db');
    }

    public function listroomcats()
    {
        $listroomcats = $this->_db->fetchAll("
			SELECT roomcat_id, roomcat_type, room_type 
			FROM roomcategories			
		");

        return $listroomcats;
    }

    public function getRoomcatsbyhotel($hotel_id)
    {
        $listroomcatsbyhotel = $this->_db->fetchAll("
			SELECT roomcat_id 
			FROM hotelrooms 
			WHERE hotel_id=".$hotel_id."	
		");

        return $listroomcatsbyhotel;
    }

    public function addRoomcats($form_values)
    {
        $roomtype_val = "";
    	//print_r($form_values); exit;
        
        for ($i = 0; $i < sizeof($form_values['roomtype_val']); $i++)
		{
			$roomtype_val .= $form_values['roomtype_val'][$i] . "|";
		}
    	
    	$room_cat = $form_values['room_cat'];
    	$status = $form_values['status'];
    	
    	$sql="INSERT INTO roomcategories (roomcat_type, room_type, is_enable)
			  VALUES ('". $room_cat . "', '" . $roomtype_val . "', " . $status . ")";

        $add_room_cat = $this->_db->exec($sql);
        if($add_room_cat)
        {
        	echo "Room Category is successfully added";
        }
    }


    public function getRoomcats($roomcat_id)
    {
        $sql="
			SELECT *
			FROM roomcategories 
			WHERE roomcat_id=" . $roomcat_id;
          
        $getRoomCat = $this->_db->fetchRow($sql);
        return $getRoomCat;
    }

    public function updateRoomcats($form_values)
    {
        $roomtype_val = "";
    	//print_r($form_values); exit;
        
        for ($i = 0; $i < sizeof($form_values['roomtype_val']); $i++)
		{
			$roomtype_val .= $form_values['roomtype_val'][$i] . "|";
		}
    	
    	$room_cat = $form_values['room_cat'];
    	$status = $form_values['status'];
    	$roomcat_id = $form_values['roomcat_id'];
    	
    	$sql = "UPDATE roomcategories
  				SET roomcat_type = '" . $room_cat . "', room_type = '" . $roomtype_val . "', is_enable = " . $status . "
  				WHERE roomcat_id = ".$roomcat_id;

        $updateroomcats = $this->_db->exec($sql);
        if($updateroomcats)
        {
        	echo "Room category is successfully updated";
        }
    }

    public function deleteRoomcats($roomcat_id)
    {
        $sql = "DELETE FROM roomcategories
			WHERE roomcat_id=".$roomcat_id."";
        $deleteroomcats = $this->_db->exec($sql);
        return $deleteroomcats;
    }
    
    public function getRoomTypeByid($roomcat_id)
    {
    	$roomtype_arr = $this->_db->fetchAll("
			SELECT room_type 
			FROM roomcategories	
			WHERE roomcat_id = " . $roomcat_id);
    	
    	return $roomtype_arr;
    }
}